﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Models;

namespace DAL
{
   public class FaTie2DAL
    {
       /// <summary>
       /// 页面开始查询所有
       /// </summary>
       /// <returns></returns>
       public static List<FaTie2> SelectAlly()
       {
           string sql = "select f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y";
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           foreach (DataRow item in dt.Rows)
           {
               FaTie2 model = new FaTie2();
               model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
               model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
               model.UserName = item["UserName"].ToString();
               model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
               list.Add(model);
           }
           return list;
       }
       /// <summary>
       /// 技术交流
       /// </summary>
       /// <returns></returns>
       public static List<FaTie2> SelectAlly1()
       {
           string sql = "select  f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y where f.UserID=y.UserID and  f.FaTieTypeid=1";
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           foreach (DataRow item in dt.Rows)
           {
               FaTie2 model = new FaTie2();
               model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
               model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
               model.UserName = item["UserName"].ToString();
               model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
               list.Add(model);
           }
           return list;
       }
       /// <summary>
       /// 作品分享
       /// </summary>
       /// <returns></returns>
       public static List<FaTie2> SelectAlly2()
       {
           string sql = "select  f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y where f.UserID=y.UserID and  f.FaTieTypeid=2";
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           foreach (DataRow item in dt.Rows)
           {
               FaTie2 model = new FaTie2();
               model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
               model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
               model.UserName = item["UserName"].ToString();
               model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
               list.Add(model);
           }
           return list;
       }
       /// <summary>
       /// 官方发布
       /// </summary>
       /// <returns></returns>
       public static List<FaTie2> SelectAlly3()
       {
           string sql = "select  f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y where f.UserID=y.UserID and  f.FaTieTypeid=3";
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           foreach (DataRow item in dt.Rows)
           {
               FaTie2 model = new FaTie2();
               model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
               model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
               model.UserName = item["UserName"].ToString();
               model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
               list.Add(model);
           }
           return list;
       }
       /// <summary>
       /// 官方发布
       /// </summary>
       /// <returns></returns>
       public static List<FaTie2> SelectAlly4()
       {
           string sql = "select  f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y where f.UserID=y.UserID and  f.FaTieTypeid=4";
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           foreach (DataRow item in dt.Rows)
           {
               FaTie2 model = new FaTie2();
               model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
               model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
               model.UserName = item["UserName"].ToString();
               model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
               list.Add(model);
           }
           return list;
       }
       public static List<FaTie2> Select(string FaTieTypeTitle)
       {
           string sql = string.Format("select  f.FaTieTypeTitle,y.UserName,f.FaTieTime,f.DianJiRate from FaTie f,Yonghu y where f.UserID=y.UserID and FaTieTypeTitle like '%{0}%'", FaTieTypeTitle);
           DataTable dt = DBHelper.Instance().GetDataTableBySql(sql);
           List<FaTie2> list = new List<FaTie2>();
           if (dt!=null&&dt.Rows.Count>0)
           {
               
               foreach (DataRow item in dt.Rows)
               {
                   FaTie2 model = new FaTie2();
                   model.FaTieTime = Convert.ToDateTime(item["FaTieTime"]);
                   model.FaTieTypeTitle = item["FaTieTypeTitle"].ToString();
                   model.UserName = item["UserName"].ToString();
                   model.DianJiRate = Convert.ToInt32(item["DianJiRate"]);
                   list.Add(model);
               }
              
           }
           return list; 
       }
    }
}
